﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZX.OA.BLL;
using ZX.OA.Model;

namespace ZXOfficeOA.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        #region 确认无误
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            return View();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="UserName">ajax传过来用户输入的用户名</param>
        /// <param name="UserPwd">ajax传过来用户输入的密码</param>
        /// <returns></returns>
        public ActionResult LoginDO(string UserName, string UserPwd)
        {
            PowerRoleBLL bll = new PowerRoleBLL();
            if (bll.Login(UserName, UserPwd) == 0)
            {
                return Content("0");
            }
            else if (bll.Login(UserName, UserPwd) == 2)
            {
                return Content("2");
            }
            else
            {
                Session["UserName"] = UserName;
                Session["UserPass"] = UserPwd;
                return Content("1");
            }
        }
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //EmployeeInfoBLL bll = new EmployeeInfoBLL();
            //bll.ShowEmp()
            return View();
        }
        public ActionResult RolePower()
        {
            return View();
        }
        public ActionResult ShowRole()
        {
            PowerRoleBLL bll = new PowerRoleBLL();
            return Json(bll.ShowRoleInfo().ToList(), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 二级菜单显示
        /// </summary>
        /// <param name="ProviceID"></param>
        /// <returns></returns>
        public ActionResult TwoPower(int ProviceID)
        {
            PowerRoleBLL bll = new PowerRoleBLL();
            List<PowerInfo> Plist = bll.ShowPower(ProviceID);
            return Json(Plist, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 人事管理
        /// </summary>
        /// <returns></returns>
        public ActionResult Employee()
        {
            EmployeeInfoBLL ebll = new EmployeeInfoBLL();
            return View(ebll.ShowEmp().ToList());
        }
        /// <summary>
        /// 公司制度
        /// </summary>
        /// <returns></returns>
        public ActionResult KnowLedgeClass()
        {
            return View();
        }
        /// <summary>
        /// 工作流
        /// </summary>
        /// <returns></returns>
        public ActionResult Schedule()
        {
            return View();
        }
        /// <summary>
        /// 工作任务
        /// </summary>
        /// <returns></returns>
        public ActionResult TaskAllot()
        {
            TaskInfoBll bll = new TaskInfoBll();
            return View(bll.GetTaskList().ToList());
        }
        /// <summary>
        /// 新闻公告
        /// </summary>
        /// <returns></returns>
        public ActionResult NewsInfo()
        {
            NewsInfoBLL bll = new NewsInfoBLL();
            return View(bll.ShowNewInfo().ToList());
        }
        /// <summary>
        ///显示会议
        /// </summary>
        /// <returns></returns>
        public ActionResult Meeting()
        {
            MeetingBll bll = new MeetingBll();
            return View(bll.Show_MeetingInfo().ToList());
        }
        /// <summary>
        ///显示会议
        /// </summary>
        /// <returns></returns>
        public ActionResult MeetingRoom()
        {
            MeetingRoomBll bll = new MeetingRoomBll();
            return View(bll.Show_MeetingRoomInfo().ToList());
        }
        /// <summary>
        /// 添加任务信息
        /// </summary>
        /// <returns></returns>
        public ActionResult AddTask()
        {
            return View();
        }
        public ActionResult Index_x()
        {
            return View();
        }
        public ActionResult Index1()
        {
            return View();
        }
        public ActionResult JCZD()
        {
            return View();
        }
        public ActionResult ShowMessage()
        {
            MessageInfoBLL bll = new MessageInfoBLL();
            return View(bll.ShowMessage());
        }
        public ActionResult AddEmploylee()
        {
            DeptBLL bll = new DeptBLL();
            ViewBag.DeptId = new SelectList(bll.ShowDeptInfo(), "DeptID", "DeptName");
            return View();
        }
        #endregion
        public ActionResult AddMessage()
        {
            MessageGroupBLL bll = new MessageGroupBLL();
            ViewBag.MessageGroupId = new SelectList(bll.ShowMessageGroup(),"MessageGroupId","MessageGroupName");
            return View();
        }
        public ActionResult AddMessageDo(MessageInfo m)
        {
            MessageInfoBLL bll=new MessageInfoBLL();
            if(bll.AddMessage(m)>0)
            {
                return Content("<script>alert('添加成功');location.href='/Home/ShowMessage'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='/Home/AddMessage'</script>");
            }
        }
        public ActionResult Leave()
        {
            LeaveBll bll = new LeaveBll();
            return View();
        }
        /// <summary>
        /// 根据ID删除通讯录信息
        /// </summary>
        /// <returns></returns>
        public ActionResult DelMessage(int nid)
        {
            MessageInfoBLL bll=new MessageInfoBLL ();
            if(bll.DeleteMessage(nid)>0)
            {
                return Content("<script>alert('删除成功！');location.href='/Home/ShowMessage'</script>");
            }
            return Content("<script>alert('服务器忙！');location.href='/Home/ShowMessage'</script>");
        }
        /// <summary>
        /// 修改通讯录
        /// </summary>
        /// <returns></returns>
        public ActionResult updateMessage(int nid)
        {
            MessageGroupBLL bl = new MessageGroupBLL();
            MessageInfoBLL bll = new MessageInfoBLL();
            ViewBag.MessageGroupId = new SelectList(bl.ShowMessageGroup(), "MessageGroupId", "MessageGroupName", bll.GetMessageByMessageID(nid).MessageGroupId);
            return View(bll.GetMessageByMessageID(nid));
        }
        /// <summary>
        /// 修改通讯录信息
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ActionResult updateMessage(MessageInfo m)
        {
            MessageInfoBLL bll = new MessageInfoBLL();
            if (bll.UpdateMessage(m) > 0)
            {
                return Content("<script>alert('修改成功！');location.href='/Home/ShowMessage'</script>");
            }
            return Content("<script>alert('服务器忙！');location.href='/Home/ShowMessage'</script>");
        }
        /// <summary>
        /// 考勤信息
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowAttendance()
        {
            AttendanceInfoBLL bll = new AttendanceInfoBLL();
            return View(bll.ShowAttendanceInfo());
        }
        /// <summary>
        /// 获取公司资产信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Stationery()
        {
            StationeryInfoBll bll = new StationeryInfoBll();
            return View(bll.GetStationery());
        }
    }
}
